<html>
<head><meta charset="utf-8"><title>Make TyKind Copy and change ty.kind() to … compiler-team#363 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html">Make TyKind Copy and change ty.kind() to … compiler-team#363</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210558103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210558103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210558103">(Sep 18 2020 at 18:28)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/363">Make TyKind Copy and change ty.kind() to return TyKind instead of &amp;TyKind #363</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="210560588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210560588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210560588">(Sep 18 2020 at 18:48)</a>:</h4>
<p>I realized this change can be split into multiple sub PRs, so it might not even deserve an MCP. cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span> <span class="user-mention" data-user-id="255061">@LeSeulArtichaut</span> I guess this is the most relevant for you rn. Would just go ahead and implement this myself if I get an ok here :)</p>



<a name="210561139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210561139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210561139">(Sep 18 2020 at 18:53)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="492">@T-compiler</span>: Proposal <a href="https://github.com/rust-lang/compiler-team/issues/363#issuecomment-695031579">#363</a> has been seconded, and will be approved in 10 days if no objections are raised.</p>



<a name="210561199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210561199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210561199">(Sep 18 2020 at 18:53)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> I am in favor of the plan, however you package it up, subject to measurements of course that show it's not a perf regression. (I think it's definitely an ergonomics improvement.)</p>



<a name="210572034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210572034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210572034">(Sep 18 2020 at 20:32)</a>:</h4>
<p>About ergonomics: when first investigation, I found some (rare) cases where the borrow checker was complaining (I don't remember the specifics though, but it was fixable by changing the code a bit). Though I think this is minor compared to all the pattern matching and <code>*ty.kind()</code></p>



<a name="210572790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210572790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210572790">(Sep 18 2020 at 20:40)</a>:</h4>
<p>I just remembered you found this other issue <span class="user-mention" data-user-id="255061">@LeSeulArtichaut</span> , but I guess <span class="user-mention" data-user-id="216206">@lcnr</span> will encounter it too and either find a solution  or w'ell discuss it then</p>



<a name="210572795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210572795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210572795">(Sep 18 2020 at 20:40)</a>:</h4>
<p>The only concern I might personally have is <a href="#narrow/stream/144729-wg-traits/topic/fn.20kind%28%29.20-.3E.20TypeKind.20or.20-.3E.20.26TypeKind/near/208444172">this</a>: if you need to return a reference, you can't make it live as long as the input <code>kind</code>. This made it impossible to return a <code>&amp;TyKind</code> when using the <code>ty.kind()</code> method. Also note that, as it's a trait implementation, we can't change the return type.</p>
<p>In that case we can work around that by not invoking <code>ty.kind()</code> and accessing <code>ty.kind</code> directly as we're in <code>rustc_middle</code>, but if we want to keep the <code>kind</code> private, this means that such a code in some other crate won't be possible.</p>



<a name="210572876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210572876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210572876">(Sep 18 2020 at 20:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363/near/210572790">said</a>:</p>
<blockquote>
<p>I just remembered you found this other issue <span class="user-mention silent" data-user-id="255061">LeSeulArtichaut</span> , but I guess <span class="user-mention silent" data-user-id="216206">lcnr</span> will encounter it too and either find a solution  or w'ell discuss it then</p>
</blockquote>
<p>I was writing about that <span aria-label="grinning face with smiling eyes" class="emoji emoji-1f601" role="img" title="grinning face with smiling eyes">:grinning_face_with_smiling_eyes:</span></p>



<a name="210573047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210573047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210573047">(Sep 18 2020 at 20:42)</a>:</h4>
<p>tbh, we can change <code>EncodableWithShorthand</code> to return <code>Self::Variant</code> directly. Both <code>ty::PredicateKind</code> and <code>ty::TyKind</code> should really be <code>Copy</code>.</p>



<a name="210620639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620639">(Sep 19 2020 at 15:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363/near/210560588">said</a>:</p>
<blockquote>
<p>I realized this change can be split into multiple sub PRs, so it might not even deserve an MCP. cc <span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <span class="user-mention silent" data-user-id="255061">LeSeulArtichaut</span> I guess this is the most relevant for you rn. Would just go ahead and implement this myself if I get an ok here :)</p>
</blockquote>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> Btw I'm willing to help you make the refractor if you want. I had a branch where I started the work but I think I wiped it out :/</p>



<a name="210620738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620738">(Sep 19 2020 at 15:33)</a>:</h4>
<p>I guess the easiest way to do this is:</p>
<p>Making <code>TyKind</code> <code>Copy</code> ~&gt; A few PRs changing <code>ty.kind()</code> to <code>*ty.kind()</code> and removing all <code>&amp;ty::Variant</code> ~&gt; actually change <code>fn kind</code></p>



<a name="210620747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620747">(Sep 19 2020 at 15:33)</a>:</h4>
<p>so yeah, if you want we can split step 2 here</p>



<a name="210620792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620792">(Sep 19 2020 at 15:34)</a>:</h4>
<p>Would be quite helpful for me <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="210620805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620805">(Sep 19 2020 at 15:34)</a>:</h4>
<p>Actually I have a stash saved with 60 lines changed</p>



<a name="210620857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620857">(Sep 19 2020 at 15:35)</a>:</h4>
<p>Strategically named "Make <code>ty.kind()</code> return <code>TyKind</code>". Otherwise I don't think I would have retrieved it :D</p>



<a name="210620906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/210620906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#210620906">(Sep 19 2020 at 15:36)</a>:</h4>
<p>Since the MCP is now seconded, do you want me to push that somewhere?</p>



<a name="211848284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211848284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211848284">(Sep 30 2020 at 22:29)</a>:</h4>
<p>This proposal has been accepted: <a href="https://github.com/rust-lang/compiler-team/issues/363">#363</a>.</p>



<a name="211927338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211927338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211927338">(Oct 01 2020 at 15:23)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> wait what we made it fast enough to be able to improve perf now??</p>



<a name="211927364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211927364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211927364">(Oct 01 2020 at 15:23)</a>:</h4>
<p>err small enough</p>



<a name="211927395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211927395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211927395">(Oct 01 2020 at 15:23)</a>:</h4>
<p>I guess it makes sense, before LLVM might've loaded the components separately</p>



<a name="211929196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211929196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211929196">(Oct 01 2020 at 15:35)</a>:</h4>
<p>I think we do, will have to perf the PRs itself to be sure though</p>



<a name="211929302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211929302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211929302">(Oct 01 2020 at 15:36)</a>:</h4>
<p>I mostly added that line because of <code>Relate</code></p>



<a name="211929427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/211929427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#211929427">(Oct 01 2020 at 15:37)</a>:</h4>
<p>where going from <code>&amp;T</code> to <code>T</code> gave a small perf benefit</p>



<a name="212098451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212098451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212098451">(Oct 02 2020 at 16:35)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> <span class="user-mention" data-user-id="116009">@nikomatsakis</span> I have now changed 130 files and I'm facing the first "cannot return value referencing temporary value" problem: <a href="https://github.com/rust-lang/rust/blob/a585aaefb662ae26f8675955f26fad9be4fea96b/compiler/rustc_typeck/src/check/cast.rs#L83-L147"><code>FnCtxt::pointer_kind</code></a>.</p>
<p>Here we want to return a <code>PointerKind&lt;'tcx&gt;</code> that we extract from a <code>ty::Param</code>, but since we now copy the <code>TyKind</code>, we can't return a reference to it.<br>
Is the only way out of this problem is to change the definition of <code>PointerKind</code> to own the <code>ParamTy</code>? Or did I miss an easy solution?</p>



<a name="212115307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212115307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212115307">(Oct 02 2020 at 19:07)</a>:</h4>
<p>I think directly using <code>ParamTy</code> and <code>ProjectionTy</code> is fine here</p>



<a name="212115391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212115391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212115391">(Oct 02 2020 at 19:08)</a>:</h4>
<p>they both have the same size as the <code>OfOpaque</code> variant, so I guess that shouldn't hurt perf</p>



<a name="212169287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212169287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212169287">(Oct 03 2020 at 12:26)</a>:</h4>
<p>Opened <a href="https://github.com/rust-lang/rust/issues/77482">#77482</a>, could someone (cc <span class="user-mention" data-user-id="216206">@lcnr</span>) request a perf run?</p>



<a name="212460531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212460531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212460531">(Oct 06 2020 at 17:39)</a>:</h4>
<p>From a private convo with <span class="user-mention" data-user-id="255061">@LeSeulArtichaut</span> about the negative perf impact <a href="https://github.com/rust-lang/rust/pull/77482#issuecomment-703167312">https://github.com/rust-lang/rust/pull/77482#issuecomment-703167312</a>:</p>
<p>I think I know the issue<br>
and we can't fix it<br>
<a href="https://github.com/rust-lang/rust/blob/9fdaeb393a16951f6fdef087193fef576e36aba6/compiler/rustc_middle/src/ty/structural_impls.rs#L936">https://github.com/rust-lang/rust/blob/9fdaeb393a16951f6fdef087193fef576e36aba6/compiler/rustc_middle/src/ty/structural_impls.rs#L936</a></p>
<p><code>TypeFoldable</code> takes self by reference</p>
<p>so if <code>kind()</code> returns <code>&amp;TyKind</code>, we branch on the discriminant and then call <code>subelement.fold_with</code> with <code>ty_ptr_value + offset</code></p>
<p>if <code>kind()</code> returns <code>TyKind</code>, we also branch on the discriminant but then have to copy the subelements on the stack and take a reference to that</p>
<p>and this has the same issue</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[allow(rustc::usage_of_ty_tykind)]</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Borrow</span><span class="o">&lt;</span><span class="n">TyKind</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Interned</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="p">,</span><span class="w"> </span><span class="n">TyS</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">borrow</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="nc">TyKind</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="bp">self</span><span class="p">.</span><span class="mf">0.</span><span class="n">kind</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212460585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212460585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212460585">(Oct 06 2020 at 17:39)</a>:</h4>
<p>(cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span> as the second of the MCP)</p>



<a name="212461206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461206">(Oct 06 2020 at 17:45)</a>:</h4>
<blockquote>
<p>TypeFoldable takes self by reference</p>
</blockquote>
<p>this reminds me - is there a reason it takes the type by reference? I glanced at <code>resolve_vars_if_possible</code> and in the common case that it doesn't need substitions it has to clone the type</p>



<a name="212461218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461218">(Oct 06 2020 at 17:45)</a>:</h4>
<p>maybe we could make it take the type by value?</p>



<a name="212461243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461243">(Oct 06 2020 at 17:46)</a>:</h4>
<p>because <code>TypeFoldable</code> is also used for types which really shouldn't be folded imo</p>



<a name="212461337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461337">(Oct 06 2020 at 17:46)</a>:</h4>
<p>what does that mean?</p>



<a name="212461343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461343">(Oct 06 2020 at 17:46)</a>:</h4>
<p>or wait, that's actually not it, we have to clone them anyways, so why aren't we doing so</p>



<a name="212461362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461362">(Oct 06 2020 at 17:46)</a>:</h4>
<p><span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> I might have been overthinking this</p>



<a name="212461390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461390">(Oct 06 2020 at 17:46)</a>:</h4>
<p>yeah if they need to be cloned the caller can always clone them</p>



<a name="212461400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461400">(Oct 06 2020 at 17:47)</a>:</h4>
<p>We are implementing <code>TypeFoldable</code> for things like <code>mir::Body</code></p>



<a name="212461439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461439">(Oct 06 2020 at 17:47)</a>:</h4>
<p>where cloning is really expensive, but that doesn't actually seem like a reason to not take it by value</p>



<a name="212461498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461498">(Oct 06 2020 at 17:47)</a>:</h4>
<p>considering that we have to clone it anyways (which I didn't realize up until now)</p>



<a name="212461605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461605">(Oct 06 2020 at 17:48)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_infer/infer/mod.rs.html#1360">https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_infer/infer/mod.rs.html#1360</a></p>



<a name="212461669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461669">(Oct 06 2020 at 17:49)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> are you interested in making that pr? ;)</p>



<a name="212461684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461684">(Oct 06 2020 at 17:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363/near/212461669">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> are you interested in making that pr? ;)</p>
</blockquote>
<p>god no</p>



<a name="212461694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461694">(Oct 06 2020 at 17:49)</a>:</h4>
<p>that one would be enormous</p>



<a name="212461819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461819">(Oct 06 2020 at 17:50)</a>:</h4>
<p>changing <code>Relate</code> was already bad enough <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> <a href="https://github.com/rust-lang/rust/issues/73705">#73705</a></p>



<a name="212461869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461869">(Oct 06 2020 at 17:50)</a>:</h4>
<p>if I made a such a PR, do you think it would be accepted?</p>



<a name="212461916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212461916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212461916">(Oct 06 2020 at 17:51)</a>:</h4>
<p>after an MCP and neutral/good perf results.. yeah</p>



<a name="212462098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462098">(Oct 06 2020 at 17:52)</a>:</h4>
<blockquote>
<p>considering that we have to clone it anyways (which I didn't realize up until now)</p>
</blockquote>
<p>we should probably move that into its own topic, but I do realize that's not quite right</p>



<a name="212462141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462141">(Oct 06 2020 at 17:53)</a>:</h4>
<p>is there anything else that should change other than <code>resolve_vars_if_possible</code>? Maybe <code>fold_with</code> and <code>super_fold_with</code>?</p>



<a name="212462190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462190">(Oct 06 2020 at 17:53)</a>:</h4>
<p>wait, you mean you want to only change <code>resolve_vars_if_possible</code>?</p>



<a name="212462223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462223">(Oct 06 2020 at 17:53)</a>:</h4>
<p>I have no idea how the compiler works <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> which is why I asked you to do it first</p>



<a name="212462347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462347">(Oct 06 2020 at 17:54)</a>:</h4>
<p>One issue I have is stuff like <code>impl&lt;'tcx, T: TypeFoldable&lt;'tcx&gt;&gt; TypeFoldable&lt;'tcx&gt; for Vec&lt;T&gt; { ... }</code></p>



<a name="212462424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462424">(Oct 06 2020 at 17:55)</a>:</h4>
<p>rn we can simply implement fold as <code>vec.iter().map(|e| e.fold_with(folder)).collect())</code></p>



<a name="212462524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462524">(Oct 06 2020 at 17:56)</a>:</h4>
<p><code>into_iter()</code> after my change even</p>



<a name="212462541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462541">(Oct 06 2020 at 17:56)</a>:</h4>
<p>then it can reuse the allocation</p>



<a name="212462555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462555">(Oct 06 2020 at 17:56)</a>:</h4>
<p>yeah, but that means that we rely on specialization to not reallocate</p>



<a name="212462575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462575">(Oct 06 2020 at 17:56)</a>:</h4>
<p>and do we have the same for <code>HashMap</code>, <code>IndexVec</code> etc</p>



<a name="212462597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462597">(Oct 06 2020 at 17:56)</a>:</h4>
<p>it's no worse than now, where it <em>always</em> reallocates</p>



<a name="212462631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462631">(Oct 06 2020 at 17:57)</a>:</h4>
<p>but when taking <code>T</code> by value it would then allocate <em>twice</em></p>



<a name="212462682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462682">(Oct 06 2020 at 17:57)</a>:</h4>
<p>where's the second one?</p>



<a name="212462713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462713">(Oct 06 2020 at 17:58)</a>:</h4>
<p>outside of <code>fold_with</code></p>



<a name="212462871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462871">(Oct 06 2020 at 17:58)</a>:</h4>
<p>we now have <code>thing_ref.clone().fold_with(&amp;mut visitor)</code></p>



<a name="212462904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212462904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212462904">(Oct 06 2020 at 17:59)</a>:</h4>
<p>ah I see what you mean</p>



<a name="212463106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212463106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212463106">(Oct 06 2020 at 18:00)</a>:</h4>
<p>FWIW the only collections this is implemented on is Vec, Box[T], and IndexVec <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/fold/trait.TypeFoldable.html#impl-TypeFoldable%3C%27tcx%3E-for-Box%3CT%3E">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/fold/trait.TypeFoldable.html#impl-TypeFoldable%3C%27tcx%3E-for-Box%3CT%3E</a></p>



<a name="212463390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212463390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212463390">(Oct 06 2020 at 18:02)</a>:</h4>
<p>hmm, that does not too bad actually</p>



<a name="212463425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212463425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212463425">(Oct 06 2020 at 18:02)</a>:</h4>
<p>So <code>Box</code> has the same problem as <code>Box&lt;[T]&gt;</code>, but that's still not too bad</p>



<a name="212464031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212464031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212464031">(Oct 06 2020 at 18:08)</a>:</h4>
<p>so yeah, it seems worth trying <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> This change is really large though and I can't think of a good way to split it into smaller chunks</p>



<a name="212464069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212464069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212464069">(Oct 06 2020 at 18:08)</a>:</h4>
<p>It seems mostly mechanical, I wonder if rust-analyzer has good enough refactor support</p>



<a name="212465662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212465662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212465662">(Oct 06 2020 at 18:22)</a>:</h4>
<p>hmm, might be worth it to create an MCP for this with a note that this refactoring might fail</p>



<a name="212465827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212465827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212465827">(Oct 06 2020 at 18:23)</a>:</h4>
<p>though the question is if there is someone to actually implement all of this <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="212476210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/212476210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#212476210">(Oct 06 2020 at 19:50)</a>:</h4>
<p><span aria-label="rolling eyes" class="emoji emoji-1f644" role="img" title="rolling eyes">:rolling_eyes:</span></p>



<a name="213642153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Make%20TyKind%20Copy%20and%20change%20ty.kind%28%29%20to%20%E2%80%A6%20compiler-team%23363/near/213642153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind().20to.20.E2.80.A6.20compiler-team.23363.html#213642153">(Oct 17 2020 at 08:52)</a>:</h4>
<p>well, opened <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Change.20type.20folding.20to.20take.20self.20by.20value.20compiler-team.23371">https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Change.20type.20folding.20to.20take.20self.20by.20value.20compiler-team.23371</a> and will probably implement this myself</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>